home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / utility / spawn.s < prev    next >
Text File  |  1985-11-19  |  4KB  |  94 lines

  1.  ; Program Name: SPAWN.S
  2.  ; Version 1.003
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in "PC-relative" mode and save with a TTP extension. 
  7.  
  8.  ; Program Function:
  9.  
  10.  ;     Spawn the TOS or PRG process typed on the command line.  Create a disk
  11.  ; file which is to be identified by the name of the spawned program with a
  12.  ; DAT suffix.  The disk file is to reside in the same directory as does the
  13.  ; spawned process.
  14.  
  15.  ;     If the program to be executed has any halt or wait instructions, such
  16.  ; as wait for a keypress, etc., you must remember that execution of the
  17.  ; spawned process will not terminate until those conditions are satisfied.
  18.  
  19. release_excess_memory:
  20.  lea        -$82(pc), a3        ; Put "command line" address in A3.
  21.  lea        -$80(a3), a1        ; Put "basepage" address in A1.
  22.  lea        program_end, a0     ; Put "end of program" address in A0.
  23.  trap       #6                  ; Calculate program size and release memory.
  24.  lea        stack, a7           ; Point A7 to this program's stack.
  25.  
  26. process_command_line_parameters:
  27.  lea        command_line, a4    ; Fetch location to contain command line.
  28.  movem.l    (a3), d0-d3         ; Move 16 bytes of command line to 4 registers.
  29.  movem.l    d0-d3, (a4)         ; Move them to address "command_line".
  30.  move.b     (a3)+, d0           ; Fetch command line ASCII character count.
  31.  ext.w      d0                  ; Extend to word for next instruction.
  32.  move.b     #0, 1(a4,d0.w)      ; Store a null at end of string.
  33.  
  34.  lea        program_name, a0    ; Fetch address of pointer to command line.
  35.  move.l     a3, (a0)            ; Store address of command line string at
  36.                                 ; pointer.
  37.  move.b     #0, 0(a3,d0.w)      ; Replace $0D at end of command line input
  38.                                 ; in basepage with a NULL.
  39. insert_filename_suffix:
  40.  move.b     #$44, -2(a4,d0.w)   ; Insert letter 'D'.
  41.  move.b     #$41, -1(a4,d0.w)   ; Insert letter 'A'.
  42.  move.b     #$54,  0(a4,d0.w)   ; Insert letter 'T'.
  43.  
  44. create_file:              
  45.  move.w     #0, -(sp)           ; File attribute = read/write.
  46.  pea        filename            ; Will be name of spawned process + .DAT.
  47.  move.w     #$3C, -(sp)         ; Function = f_create = GEMDOS $3C.
  48.  trap       #1                  ; File handle is returned in D0.
  49.  addq.l     #8, sp
  50.  lea        file_handle, a0     ; Store returned file handle to be used when
  51.  move.w     d0, (a0)            ; the file is closed later.
  52.  
  53. redirect_output:                ; Exchange file handle with screen's handle.
  54.  move.w     d0, -(sp)           ; This is the disk file's handle.
  55.  move.w     #1, -(sp)           ; This is the video screen's handle.
  56.  move.w     #$46, -(sp)         ; Function = f_force = GEMDOS $46.
  57.  trap       #1
  58.  addq.l     #6, sp
  59.  
  60. load_and_execute_program:     
  61.  pea        environ_string
  62.  pea        command_string
  63.  pea        (a3)                ; A3 contains address of program name string.
  64.  move.w     #0, -(sp)           ; Load and Go option.
  65.  move.w     #$4B, -(sp)         ; Function = GEMDOS $4B = p_exec.
  66.  trap       #1                 
  67.  lea        $10(a7), sp         ; Reposition stack pointer.         
  68.  
  69. close_file:                    
  70.  move.w     file_handle, -(sp) 
  71.  move.w     #$3E, -(sp)         ; Function = GEMDOS $3E = f_close.
  72.  trap       #1
  73.  addq.l     #4, sp
  74.  
  75. terminate:                
  76.  move.w     #0, -(sp)
  77.  trap       #1
  78.  
  79.  data
  80. environ_string:  dc.b    "TERM",0
  81. command_string:  dc.b    0
  82.  align
  83.  bss
  84. file_handle:     ds.w    1     ; Handle for the disk file named below.
  85. command_line:    ds.b    1     ; Unused character count will go here.
  86. filename:        ds.b   15     ; File name for redirected output.    
  87. program_name:    ds.l    1     ; Pointer to name in basepage command line.
  88.                  ds.l   96     ; Program stack.
  89. stack:           ds.l    0     ; Address of program stack.
  90. program_end:     ds.l    0
  91.  end
  92.  
  93.  
  94.